package services

import (
	"context"
	db "dhuviewer/db_query"

	"github.com/google/uuid"
	"github.com/labstack/gommon/log"
)

//must Upper letter
// func TestCreate() {
// 	res, err := queries.CreateLogin(context.Background(), db.CreateLoginParams{
// 		Email:    "admin@local.host",
// 		Password: "fff267419eac38a6340a410fb6239f3c5e01439ee856e9e635c8ac4840006025",
// 	})
// 	if err != nil {
// 		log.Info("error:", err)
// 	}
// 	fmt.Println(res)
// }

func CreateLogin(email string, password string) (uuid.UUID, error) {
	res, err := queries.CreateLogin(context.Background(), db.CreateLoginParams{
		Email:    email,
		Password: password,
	})
	if err != nil {
		log.Info("error:", err)
		return uuid.Nil, err
	}
	// fmt.Println(res)
	return res.Uid, nil
}

func LoginByEmail(email string) (error, db.Login) {
	loginData, err := queries.GetLoginByEmail(context.Background(), email)
	if err != nil {
		log.Info("error:", err)
		return err, db.Login{}
	}
	return err, loginData
}
